﻿Imports Microsoft.VisualBasic

Public Class AlertClass
    Public Function AlertBox(ByVal page As Page, ByVal message As String) As Integer
        If Not page.ClientScript.IsStartupScriptRegistered("Alert") Then
            page.ClientScript.RegisterStartupScript(page.GetType(), "Alert", ScriptBuilder("Sexy.alert('" & message & "');"), True)
            Return 1
        End If
    End Function

    Public Sub InfoBox(ByVal page As Page, ByVal message As String, ByVal redirect As String)
        If Not page.ClientScript.IsStartupScriptRegistered("Infomation") Then
            page.ClientScript.RegisterStartupScript(page.GetType(), "Infomation", ScriptBuilder("Sexy.info('" & message & "','" & redirect & "');"), True)
        End If
    End Sub

    Public Sub ErrorBox(ByVal page As Page, ByVal message As String)
        If Not page.ClientScript.IsStartupScriptRegistered("Error") Then
            page.ClientScript.RegisterStartupScript(page.GetType(), "Error", ScriptBuilder("Sexy.error('" & message & "');"), True)
        End If
    End Sub

    Public Function ScriptBuilder(ByVal mess As String) As String
        Dim sb As New StringBuilder

        sb.Append("$(document).ready(function () {")
        sb.Append("" & mess & "")
        sb.Append("});")

        Return sb.ToString
    End Function
End Class
